package com.ruoyi.web.controller.zzw;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.service.ISysNoticeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZzwUserInfo;
import com.ruoyi.system.service.IZzwUserInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小程序用户信息Controller
 *
 * @author linzhaojie
 * @date 2024-06-02
 */
@RestController
@RequestMapping("/zzw/userInfo")
public class ZzwUserInfoController extends BaseController
{
    @Autowired
    private IZzwUserInfoService zzwUserInfoService;

    @Autowired
    private ISysNoticeService noticeService;
    /**
     * 查询小程序用户信息列表
     */
//    @PreAuthorize("@ss.hasPermi('zzwUserInfo:zzwUserInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZzwUserInfo zzwUserInfo)
    {
        startPage();
        List<ZzwUserInfo> list = zzwUserInfoService.selectZzwUserInfoList(zzwUserInfo);
        return getDataTable(list);
    }
    /**
     * 根据通知公告编号获取详细信息
     */
    @GetMapping("/notice/list")
    public TableDataInfo list(SysNotice notice)
    {
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    @PostMapping("/downList")
    public TableDataInfo downList(@RequestBody ZzwUserInfo zzwUserInfo)
    {
        List<ZzwUserInfo> list =zzwUserInfoService.selectDownZzwUserInfoByOpenid(zzwUserInfo);
        return getDataTable(list);
    }

    /**
     * 根据openid获取小程序用户信息详细信息
     */
    @GetMapping(value = "/{openid}")
    public AjaxResult getInfo(@PathVariable("openid") String openid)
    {
        return success(zzwUserInfoService.selectZzwUserInfoByOpenid(openid));
    }

    /**
     * 获取用户信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('zzw:userInfo:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Integer id)
//    {
//        return success(zzwUserInfoService.selectZzwUserInfoById(id));
//    }


    /**
     * 导出小程序用户信息列表
     */
//    @PreAuthorize("@ss.hasPermi('zzwUserInfo:zzwUserInfo:export')")
//    @Log(title = "导出小程序用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZzwUserInfo zzwUserInfo)
    {
        List<ZzwUserInfo> list = zzwUserInfoService.selectZzwUserInfoList(zzwUserInfo);
        ExcelUtil<ZzwUserInfo> util = new ExcelUtil<ZzwUserInfo>(ZzwUserInfo.class);
        util.exportExcel(response, list, "小程序用户信息数据");
    }

    /**
     * 获取小程序用户信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('zzwUserInfo:zzwUserInfo:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Integer id)
//    {
//        return success(zzwUserInfoService.selectZzwUserInfoById(id));
//    }

    /**
     * 新增小程序用户信息
     */

    @Log(title = "小程序用户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ZzwUserInfo zzwUserInfo)
    {
        return toAjax(zzwUserInfoService.insertZzwUserInfo(zzwUserInfo));
    }

     /**
     * 修改用户信息
     */

    @PutMapping
    public AjaxResult edit(@RequestBody ZzwUserInfo zzwUserInfo)
    {
        return toAjax(zzwUserInfoService.updateZzwUserInfo(zzwUserInfo));
    }


    /**
     * 删除小程序用户信息
     */
    @PreAuthorize("@ss.hasPermi('zzwUserInfo:zzwUserInfo:remove')")
    @Log(title = "小程序用户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(zzwUserInfoService.deleteZzwUserInfoByIds(ids));
    }
}
